package com.yc.yuehui.controller;

import com.yc.yuehui.service.BizException;
import com.yc.yuehui.vo.Result;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Component
// 控制器增强 ==> AOP
@ControllerAdvice
public class MyExHandler {

    // 拦截 自定义异常
    @ResponseBody
    @ExceptionHandler(BizException.class)
    public Result handleBizException(BizException e){
        return new Result(0, e.getMessage(),null);
    }

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public Result handleBizException(Exception e){
        e.printStackTrace();
        // 扩展操作，给管理员发送短信
        return new Result(0, "业务繁忙，请稍后再试",null);
    }
}
